package net.xi.dmhome.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.xi.dmhome.entity.*;
import net.xi.dmhome.handler.Result;
import net.xi.dmhome.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: jxhu
 * @Description:展示列表控制层
 * @Date Created in 2021-02-06 15:48
 * @Modified By:
 */
@RestController
@RequestMapping("/manage")
public class ManageController {

    @Autowired
    UserService userService;
    @Autowired
    ArticleService articleService;
    @Autowired
    AritypeService aritypeService;
    @Autowired
    AritagService aritagService;
    @Autowired
    QuestionService questionService;
    @Autowired
    PostService postService;
    @Autowired
    AnswerService answerService;
    @Autowired
    CommentService commentService;

    /* @Description: 用户列表,@Param:  */
    @GetMapping("/listUser")
    public Result listUser(@RequestParam(defaultValue = "1") Integer currentPage){

        Page page = new Page(currentPage,5);
        IPage iPage = userService.page(page, new QueryWrapper<User>().orderByDesc("createtime"));

        return Result.success(iPage);

    }

    /* @Description: 文章列表,@Param:  */
    @GetMapping("/listArticle")
    public Result listArticle(@RequestParam(defaultValue = "1") Integer currentPage){

        Page page = new Page(currentPage,5);
        IPage iPage = articleService.page(page, new QueryWrapper<Article>().orderByDesc("createtime"));

        return Result.success(iPage);

    }
    /* @Description: 文章类型列表,@Param:  */
    @GetMapping("/listAritype")
    public Result listArticleType(@RequestParam(defaultValue = "1") Integer currentPage) {

        Page page = new Page(currentPage, 5);
        IPage iPage = aritypeService.page(page, new QueryWrapper<Aritype>().orderByDesc("id"));

        return Result.success(iPage);
    }

    /* @Description: 文章标签列表,@Param:  */
    @GetMapping("/listAritag")
    public Result listArticleTag(@RequestParam(defaultValue = "1") Integer currentPage) {

        Page page = new Page(currentPage, 5);
        IPage iPage = aritagService.page(page, new QueryWrapper<Aritag>().orderByDesc("id"));

        return Result.success(iPage);
    }


        /* @Description: 问题列表,@Param:  */
    @GetMapping("/listQ")
    public Result listQuestion(@RequestParam(defaultValue = "1") Integer currentPage){

        Page page = new Page(currentPage,5);
        IPage iPage = questionService.page(page, new QueryWrapper<Question>().orderByDesc("createtime"));

        return Result.success(iPage);

    }

    /* @Description: 答案列表,@Param:  */
    @GetMapping("/listA")
    public Result listAnswer(@RequestParam(defaultValue = "1") Integer currentPage){

        Page page = new Page(currentPage,5);
        IPage iPage = answerService.page(page, new QueryWrapper<Answer>().orderByDesc("createtime"));

        return Result.success(iPage);

    }

    /* @Description: 帖子列表,@Param:  */
    @GetMapping("/listPost")
    public Result listPost(@RequestParam(defaultValue = "1") Integer currentPage){

        Page page = new Page(currentPage,5);
        IPage iPage = postService.page(page, new QueryWrapper<Post>().orderByDesc("createtime"));

        return Result.success(iPage);

    }


    /* @Description: 评论列表,@Param:  */
    @GetMapping("/listComment")
    public Result listComment(@RequestParam(defaultValue = "1") Integer currentPage){

        Page page = new Page(currentPage,5);
        IPage iPage = commentService.page(page, new QueryWrapper<Comment>().orderByDesc("createtime"));

        return Result.success(iPage);

    }





}
